﻿using Sys.Core.House;
using Sys.Core.Tour;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SaleList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ListInit();

            Home mas = Master as Home;

            string headName = "售房信息";
            string queryHouseGetType = Request.QueryString["HouseGetType"].ToString();
            if (!String.IsNullOrWhiteSpace(queryHouseGetType))
            {
                if (queryHouseGetType == "Rent")
                {
                    headName = "租房信息";
                }
            }

            mas.SetHead(headName, headName, headName);
        }
    }

    #region 当前系统维护数据（暂时作废）
    //public void ListInit()
    //{
    //    var list = SaleBll.I.Entities.OrderByDescending(m => m.UpdateTime);

    //    int recordcount = list.Count();
    //    int page = Convert.ToInt32(Request.QueryString["page"]);
    //    int rows = 5;
    //    if (page == 0) { page = 1; }

    //    rep_List.DataSource = SaleBll.I.EntitiesPage(list, rows, page).ToList();
    //    rep_List.DataBind();

    //    Pager.UpdatePage(recordcount, rows, page, Request.Url.LocalPath, string.Empty);
    //}

    //public string GetFront(string id)
    //{
    //    return ImageBll.I.GetFront("Sale", id);
    //}
    #endregion

    #region BPAMS获取的数据
    public void ListInit()
    {
        //var list = BpamsBll.Instance.GetHouses().OrderByDescending(m => m.LastUpdTime).ThenByDescending(m => m.CreateTime).ThenByDescending(m => m.JoinDate);

        var houseGetType = HouseGetType.Sell;
        string queryHouseGetType = Request.QueryString["HouseGetType"];
        if (!String.IsNullOrWhiteSpace(queryHouseGetType))
        {
            if (queryHouseGetType == "Rent")
            {
                houseGetType = HouseGetType.Rent;
            }
        }
        //取得房源总数
        int recordcount = BpamsBll.Instance.GetHousesCount(houseGetType);
        //分页数
        int page = Convert.ToInt32(Request.QueryString["page"]);
        //每页个数
        int rows = 5;
        if (page == 0) { page = 1; }
        rep_List.DataSource = BpamsBll.Instance.GetHouses(houseGetType, rows * (page - 1), rows);
        rep_List.DataBind();

        Pager.UpdatePage(recordcount, rows, page, Request.Url.LocalPath, "&HouseGetType=" + houseGetType.ToString());
    }

    public string GetFront(string id)
    {
        //return ImageBll.I.GetFront("Sale", id);

        return null;
    }
    #endregion
}